import { configureStore } from '@reduxjs/toolkit';
import rootReducer from './root-reducer';
import logger from 'redux-logger';
import { debounce } from 'lodash';
import { batchedSubscribe } from 'redux-batched-subscribe';
import { persistStore } from 'redux-persist';

const store = configureStore({
  reducer: rootReducer,
  middleware: (getDefaultMiddleware) =>
    import.meta.env.DEV
      ? getDefaultMiddleware({
          serializableCheck: false,
        }).concat(logger)
      : getDefaultMiddleware({
          serializableCheck: false,
        }),
  // devTools: false,
  // preloadedState: {},
  enhancers: [batchedSubscribe(debounce((notify) => notify()))],
});

export const persistor = persistStore(store);
export default store;
